/**
 * @param {string} s
 * @return {number}
 */
var countSubstrings = function (s) {
  let count = 0,
    left = 0,
    right = left + 1

  while (left < s.length) {
    if (right > s.length) {
      left++
      right = left+1
    } else {
      if (check(s.slice(left, right))) {
        count++
      }

      right++
    }
  }

  function check(s) {
    let left = s.length % 2 == 0 ? s.length / 2 - 1 : Math.floor(s.length / 2)
    let right = Math.floor(s.length / 2)
    while (left >= 0 && right < s.length && s[left] == s[right]) {
      left--
      right++
    }
    if (right - left - 1 == s.length) return true
    return false
  }
  return count
}

countSubstrings('abc')
